/**
 * Created by sicongdu on 18-4-16.
 */
var admin_model = require("./mongo_non_student").admins
var pass_model = require("./mongo_non_student").admins_pass
var config_model = require("./mongo_non_student").configs

var admin = new admin_model({
  name: "杜思聪",
  adminNo: "superadmin",
  userInfo: {}
});

var pass = new pass_model({
  adminNo: "superadmin",
  pass: "123456"
});

var config = new config_model({
  type: "3",
  key: "superadmin",
  openId: "0000"
})

var success = {
  error_no: 0,
  error_msg: "ok"
}

var fail = {
  error_no: 1,
  error_msg: "save_error"
}

// var conditions = {type: "3"};
// var updates = {$set: {openId: "0000"}};//将用户名更新为“tiny”
// config_model.update(conditions, updates, function (error) {
//   if (error) {
//     console.error(error);
//   } else {
//     console.error("更新openid成功")
//   }
// });

admin.save((err, resin) => {
    if (err){
        fail = {
            error_no: 1,
            error_msg: "admin_save_error"
        }
        console.log(fail)
    }else{
        pass.save((err, resin) => {
            if (err){
                fail = {
                    error_no: 2,
                    error_msg: "admin_pass_save_error"
                }
                console.log(fail)
            }else{
                config.save((err, resin) => {
                    if (err){
                        fail = {
                            error_no: 3,
                            error_msg: "config_save_error"
                        }
                        console.log(fail)
                    }else{
                        console.log(success)
                    }})
            }
        });
    }
});


